package com.meevle.commands {
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.meevle.business.SetDelegate;
	import com.meevle.error.ErrorHandler;
	import com.meevle.events.GetSlotsFromSetEvent;
	import com.meevle.model.StudioModelLocator;
	import com.meevle.model.ViewModelLocator;
	import com.meevle.vo.SetVO;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	
	public class GetSlotsFromSetCommand implements ICommand, IResponder {
		
		public function GetSlotsFromSetCommand() {
			
		}
		
		// ICommand interface method
		public function execute(event:CairngormEvent):void {
			var getSlotsFromSetEvent:GetSlotsFromSetEvent = event as GetSlotsFromSetEvent;
			var m_set:SetVO = getSlotsFromSetEvent.project;

			var delegate:SetDelegate = new SetDelegate(this);
			delegate.getSlots( m_set );
			
		}
		
		//IResponder interface methods
		public function result(event:Object) : void {
				var slotsFromSet:ArrayCollection = new ArrayCollection(event.result as Array);
				StudioModelLocator.getInstance().currentSlots = slotsFromSet;
				ViewModelLocator.getInstance().error = null;
		}
		
		public function fault(event:Object) : void {
			ErrorHandler.getInstance().handleError(event as FaultEvent);
		}	
	}
}